<%@page import="cn.sendto.model.ScoreEntity"%>
<%@page import="java.util.List"%>
<%@page import="cn.sendto.mapper.ScoreMapper"%>
<%@page import="cn.sendto.mapper.IRowMapper"%>
<%@page import="cn.sendto.dbhelper.DBHelper"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%
	request.setCharacterEncoding("utf-8");
	String id = request.getParameter("courseid");
	String stuid = request.getParameter("studentid");
	String score=request.getParameter("score");
	DBHelper helper = new DBHelper();
	IRowMapper mapper = new ScoreMapper();
	String s="select * from scoreinfo where courseid=? and studentid=?";
	List<ScoreEntity> list = helper.executeQuery(s, mapper, id,stuid);
	String sql;
	if(list==null||list.size()==0)
	{
		 sql = "insert into scoreinfo (score,courseid,studentid) values (?,?,?)";
			
	}else{
		 sql = "update scoreinfo set score=? where courseid=? and studentid=?";
	}	
	int i =helper.executeInsert(sql, score,id,stuid);
	if(i>0){
		request.setAttribute("message", "添加成功");
		request.getRequestDispatcher("student_list.jsp").forward(request, response);
		
	}else{
		request.setAttribute("message", "添加失败");
		request.getRequestDispatcher("course_list.jsp").forward(request, response);
	}
	
	helper.close();
%>